/**************************************************************************
* This file is part of Hawkengine.
**
* Hawkengine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
**
* Hawkengine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
**
* You should have received a copy of the GNU Lesser General Public License
* along with Hawkengine.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

#ifndef _UTIL_H_
#define _UTIL_H_

/**************************************************************************
* Dependencies
**************************************************************************/
#include "engine/common.h"
 
/**************************************************************************
* Preprocessing
**************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

/**************************************************************************
* Types
**************************************************************************/

/**************************************************************************
* Variables
**************************************************************************/
extern const float MATRIX_IDENTITY_2[2][2];
extern const float MATRIX_IDENTITY_3[3][3];
extern const float MATRIX_IDENTITY_4[4][4];

/**************************************************************************
* Static Variables
**************************************************************************/

/**************************************************************************
* Function Prototypes
**************************************************************************/
float angle_between(const float* v1, const float* v2);
float change_scale(float val, float in_min, float in_max,
                   float out_min, float out_max);
float change_scale_without_containing(float val, float in_min, float in_max,
                                      float out_min, float out_max);
void convert_polar(float r, float theta, float* x, float* y);
void convert_spherical(float rho, float phi, float theta,
                       float* x, float* y, float* z);
void convert_to_polar(float x, float y, float* r, float* theta);
void convert_to_spherical(float x, float y, float z,
                          float* rho, float* phi, float* theta);
void cross_product(const float* v1, const float* v2, float* cross);
UCHAR count_matches(const void* obj, const void* test1, const void* test2);
BOOL decrypt_block(UCHAR* data, int size);
BOOL dijkstra(const float* weights, float max_weight, int num_vertices,
              int start_idx, float* costs);
float dot_product(const float* v1, const float* v2);
BOOL encrypt_block(UCHAR* data, int size);
BOOL file_get_extension(const char* file_name, char* file_extension);
void gesture(const touch_type* start_touch, const touch_type* current_touch,
             float* angle, float* zoom, float* dx, float* dy);
float get_distance(const float* p1, const float* p2, int dimensions);
BOOL matrix_equal(const float* a, const float* b, int rows, int cols);
BOOL matrix_invert_4(const float* m, float* out);
void matrix_multiply(const float* a, const float* b,
                     int a_rows, int a_cols, int b_cols, float* out);
void matrix_multiply_44_41(const float* a, const float* b, float* out);
void matrix_multiply_44_44(const float* a, const float* b, float* out);
void matrix_transpose(const float* m, int orig_rows, int orig_cols, float* out);
BOOL plane_line_intersection(const float* plane_normal, const float* plane_point,
                             const float* line_vector, const float* line_point,
                             float* intersect);
void plane_normal(const float* v1, const float* v2, const float* v3, float* normal);
BOOL normalize(float* vec);
void order(float* val1, float* val2);
float random_float(float min, float max);
int random_int(int min, int max);
void randomize(void);
void rotate_point(float* x, float* y, BOOL clockwise);
int round_float(float value);
BOOL segments_intersect(const float* l1p1, const float* l1p2,
                        const float* l2p1, const float* l2p2);
void set_encryption_key(const char* key);
void sort_float(float* data, int count, BOOL ascending);
void sort_int(int* data, int count, BOOL ascending);
void sort_string(char** data, int strlen, int count, BOOL ascending);
float vector_length(const float* v);

/**************************************************************************
* Function Implementations
**************************************************************************/


#ifdef __cplusplus
}
#endif

#endif
